package com.lengjing.project.component;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @Description : 区域信息配置
 * @Author : ChenYao
 * @Version : 1.0
 * @Create : Date Time: 2018/6/26 9:24
 * @Update : Date Time: 2018/6/26 9:24
 * @see :  config.MyMvcConfig.localeResolver  向容器中添加了本类的bean
 */
public class MyLocaleResover implements LocaleResolver {
    /**
     * @Description: 
     * @Author: ChenYao
     * @param:
     * @return: 
     * @throws: 
     * @CreateDate: 2018/6/26 15:49
     * @see: 
     * Note:
     */
    
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String language = request.getParameter("L");
        //获取默认的区域语言信息
        Locale locale =Locale.getDefault();
        if (!StringUtils.isEmpty(language)) {
            //zh_CN,en_US,第一个语言,第二个国家;
            String[] splits = language.split("_");
            //第一个语言,第二个国家;
            locale = new Locale(splits[0], splits[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
